package com.blinddate.context;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;

public class BaseContext {

    public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void setCurrentId(Long id) {
        threadLocal.set(id);
    }

    public static Long getCurrentId() {
        return threadLocal.get();
    }


    public static void removeCurrentId() {
        threadLocal.remove();
    }

    //获取过期时长  截止时间为第二天5点
    public static Long timeOut(){
        //获取当前时间
        LocalDateTime nowTime = LocalDateTime.now();
        //开始时间
        LocalDateTime dateStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        //结束时间
        LocalDateTime dateEnd = dateStart.plusHours(5);
        if (nowTime.isAfter(dateStart)&&nowTime.isBefore(dateEnd)){
            long endTime = dateEnd.toEpochSecond(ZoneOffset.ofHours(8));
            long time = nowTime.toEpochSecond(ZoneOffset.ofHours(8));
            return endTime-time;
        } else{
            LocalDateTime dateNextDay = dateEnd.plusDays(1);
            long endTime = dateNextDay.toEpochSecond(ZoneOffset.ofHours(8));
            long time = nowTime.toEpochSecond(ZoneOffset.ofHours(8));
            return endTime - time;
        }
    }

}
